#encoding='utf-8'
# import mimetypes


from flask import Flask, request, Response, render_template, send_from_directory, make_response, logging,jsonify
import yaml
import os
import sys
from flask_cors import CORS

# from pip._vendor import requests
from src.db import getdbdata

app = Flask(__name__)
CORS(app, supports_credentials=True)
yamlPath = os.path.dirname(os.path.realpath(sys.argv[0])) + '\\config.yaml'
# 加上 ,encoding='utf-8'，处理配置文件中含中文出现乱码的情况。
#pyinstaller -F -c src\webcontro.py
f = open(yamlPath,'r',encoding='utf-8')
cont = f.read()
service = yaml.load(cont, Loader=yaml.FullLoader)['service']
f.close()
@app.route("/")
def index():
    return render_template("index.html")
@app.route('/getrealdata/', methods=['GET'])
def downloadfile():
    if request.method == 'GET':
        dbname = request.args.get('dbname')
        task={}
        task['data']=getdbdata(dbname)
        return getdbdata(dbname)
if __name__ == '__main__':
    # print(getdbdata('MiniStation_SY'))
    app.run(host=service['ip'], port=service['port'])
